package org.example.judge.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.SneakyThrows;
import org.example.judge.mapper.ProblemCaseMapper;
import org.example.judge.service.ProblemCaseService;
import org.example.judge_common.hander.RetrunMsgException;
import org.example.judge_common.util.IdWorker;
import org.example.judge_pojo.ProblemCase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("ProblemCaseServiceImpl")
public class ProblemCaseServiceImpl extends ServiceImpl<ProblemCaseMapper, ProblemCase> implements ProblemCaseService {

    @Autowired
    private IdWorker idWorker;
    @Override
    public List<ProblemCase> getSubmitCasesByProblemId(String id) {
        QueryWrapper<ProblemCase> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("problem_id", id); //所属题目
        queryWrapper.eq("status", 0);  //需要参与后台评测的数据
        List<ProblemCase> list = this.list(queryWrapper);
        return list;
    }

    @Override
    public List<ProblemCase> listByProblemId(String problemId) {
        return this.list(new QueryWrapper<ProblemCase>().eq("problem_id",problemId));
    }

    @Override
    public List<ProblemCase> listExampleByProblemId(String problemId) {
        return this.list(
                new QueryWrapper<ProblemCase>().
                        eq("problem_id",problemId).
                        eq("ishow",0).eq("type",0));  //题面样例 and 数据样例
    }

    @SneakyThrows
    @Override
    public boolean save(ProblemCase entity){
        entity.setId(idWorker.nextId().toString());
        entity.setCreateTime(new Date());

        return super.save(entity);
    }
}
